﻿using System;
using System.Reflection;
using ERP.Business.DataTypes.Constants.Interfaces;

namespace ERP.Business.CompanyManagers.Policy
{
    public abstract class SystemConstatsManager 
    {
        private static Type GetManagerType(Type valueType)
        {
            Type mnger = null;
            Assembly assembly = Assembly.GetAssembly(typeof(SystemConstatsManager));
            mnger = assembly.GetType(string.Format("ERP.Business.CompanyManagers.Policy.Constants.{0}sManager", valueType.Name));
            return mnger;
        }

        public static void AddConstant(ConstantBase value)
        {
            System.Reflection.MethodInfo me = GetManagerType(value.GetType()).GetMethod("AddValue");
            me.Invoke(null, new object[] { value });
        }

        public static void RemoveConstant(ConstantBase value)
        {
            System.Reflection.MethodInfo me = GetManagerType(value.GetType()).GetMethod("RemoveValue");
            me.Invoke(null, new object[] { value });
        }

        public static void UpdateConstant(ConstantBase value)
        {
            System.Reflection.MethodInfo me = GetManagerType(value.GetType()).GetMethod("UpdateValue");
            me.Invoke(null, new object[] { value });
        }

        public static ERP.Business.DataTypes.BaseTypes.BaseCollection<ConstantBase> GetConstantValues(Type constantType)
        {
            System.Reflection.MethodInfo me = GetManagerType(constantType).GetMethod("GetValues");
            return (ERP.Business.DataTypes.BaseTypes.BaseCollection<ConstantBase>)me.Invoke(null, null);
        }
    }
}